/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JDialogPlayBackTime.java
 *
 * Created on 2009-11-24, 19:11:16
 */

/**
 *
 * @author Administrator
 */

package ClientDemo;

import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.examples.win32.W32API.HWND;
import com.sun.jna.ptr.IntByReference;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/*****************************************************************************
 *类 ：JDialogPlayBackByTime
 *类描述 ：远程按时间回放操作
 ****************************************************************************/
public class JDialogPlayBackByTime extends javax.swing.JDialog {

    static HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
    NativeLong m_lUserID;//用户ID
    NativeLong m_lPlayHandle;//播放句柄
    NativeLong m_lLoadHandle;//下载句柄
    String m_sDeviceIP;//设备IP
    int m_iChanShowNum;//回放通道
    boolean m_bSound;//是否开启声音
    boolean m_bPause;//是否已暂停
    boolean m_bTimeSave;//是否在保存

    Timer Downloadtimer;//下载用定时器
    Timer Playbacktimer;//回放用定时器


    /*************************************************
    函数:      JDialogPlayBackByTime
    函数描述:  构造函数   Creates new form JDialogPlayBackByTime
     *************************************************/
    public JDialogPlayBackByTime(java.awt.Frame parent, boolean modal, NativeLong lUserID, String sIP) {
        super(parent, modal);
        initComponents();
        initialDialog();
        m_lUserID = lUserID;
        m_lPlayHandle = new NativeLong(-1);
        m_lLoadHandle = new NativeLong(-1);
        m_iChanShowNum = 0;
        m_sDeviceIP = sIP;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelTime = new javax.swing.JPanel();
        jTextFieldsHour = new javax.swing.JTextField();
        jTextFieldeHour = new javax.swing.JTextField();
        jTextFieldeYear = new javax.swing.JTextField();
        jLabelEndTime = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldsYear = new javax.swing.JTextField();
        jLabelStartTime = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldsSecond = new javax.swing.JTextField();
        jTextFieldsDay = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldeSecond = new javax.swing.JTextField();
        jTextFieldsMonth = new javax.swing.JTextField();
        jTextFieldeDay = new javax.swing.JTextField();
        jTextFieldsMinute = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jTextFieldeMinute = new javax.swing.JTextField();
        jTextFieldeMonth = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jTextFieldChanNum = new javax.swing.JTextField();
        jPanelPlayControl = new javax.swing.JPanel();
        panelPlay = new java.awt.Panel();
        jSliderAudio = new javax.swing.JSlider();
        jToolBar1 = new javax.swing.JToolBar();
        jButtonPlay = new javax.swing.JButton();
        jButtonStop = new javax.swing.JButton();
        jLabel14 = new javax.swing.JLabel();
        jButtonSlow = new javax.swing.JButton();
        jButtonFast = new javax.swing.JButton();
        jLabel15 = new javax.swing.JLabel();
        jButtonCapture = new javax.swing.JButton();
        jLabel16 = new javax.swing.JLabel();
        jButtonAudio = new javax.swing.JButton();
        jButtonDownload = new javax.swing.JButton();
        jButtonSave = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("按时间回放");

        jPanelTime.setBorder(javax.swing.BorderFactory.createTitledBorder("录像时间"));

        jLabelEndTime.setText("结束时间");

        jLabel1.setText("年");

        jLabelStartTime.setText("开始时间");

        jLabel3.setText("日");

        jLabel6.setText("秒");

        jLabel9.setText("日");

        jLabel12.setText("秒");

        jLabel8.setText("月");

        jLabel5.setText("分");

        jLabel11.setText("分");

        jLabel2.setText("月");

        jLabel7.setText("年");

        jLabel10.setText("时");

        jLabel4.setText("时");

        jLabel13.setText("通道号");

        jTextFieldChanNum.setText("1");

        javax.swing.GroupLayout jPanelTimeLayout = new javax.swing.GroupLayout(jPanelTime);
        jPanelTime.setLayout(jPanelTimeLayout);
        jPanelTimeLayout.setHorizontalGroup(
            jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTimeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelTimeLayout.createSequentialGroup()
                        .addComponent(jLabelStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldsYear, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldsMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldsDay, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanelTimeLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jTextFieldsHour, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(10, 10, 10)
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldsMinute, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldsSecond, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel13)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldChanNum, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanelTimeLayout.createSequentialGroup()
                        .addComponent(jLabelEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldeYear, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldeMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTextFieldeDay, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelTimeLayout.createSequentialGroup()
                                .addGap(20, 20, 20)
                                .addComponent(jTextFieldeHour, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(10, 10, 10)
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldeMinute, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jTextFieldeSecond, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanelTimeLayout.setVerticalGroup(
            jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTimeLayout.createSequentialGroup()
                .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelStartTime, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldsYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldsMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldsDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldsHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldsMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldsSecond, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jTextFieldChanNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelTimeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabelEndTime, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldeYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jTextFieldeMonth, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jTextFieldeDay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(jTextFieldeHour, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jTextFieldeMinute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jTextFieldeSecond, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel12)))
        );

        jPanelPlayControl.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("宋体", 0, 12), new java.awt.Color(204, 255, 204))); // NOI18N

        panelPlay.setBackground(new java.awt.Color(234, 255, 255));

        javax.swing.GroupLayout panelPlayLayout = new javax.swing.GroupLayout(panelPlay);
        panelPlay.setLayout(panelPlayLayout);
        panelPlayLayout.setHorizontalGroup(
            panelPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 520, Short.MAX_VALUE)
        );
        panelPlayLayout.setVerticalGroup(
            panelPlayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 378, Short.MAX_VALUE)
        );

        jSliderAudio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jSliderAudioMouseReleased(evt);
            }
        });

        jToolBar1.setRollover(true);

        jButtonPlay.setBackground(new java.awt.Color(204, 204, 255));
        jButtonPlay.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonPlay.setForeground(new java.awt.Color(51, 51, 255));
        jButtonPlay.setText("Play");
        jButtonPlay.setFocusable(false);
        jButtonPlay.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonPlay.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPlayActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonPlay);

        jButtonStop.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonStop.setForeground(new java.awt.Color(51, 51, 255));
        jButtonStop.setText("Stop");
        jButtonStop.setFocusable(false);
        jButtonStop.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonStop.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonStop.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonStopActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonStop);

        jLabel14.setText("      ");
        jToolBar1.add(jLabel14);

        jButtonSlow.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonSlow.setForeground(new java.awt.Color(51, 51, 255));
        jButtonSlow.setText("Slow");
        jButtonSlow.setFocusable(false);
        jButtonSlow.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonSlow.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonSlow.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSlowActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonSlow);

        jButtonFast.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonFast.setForeground(new java.awt.Color(51, 51, 255));
        jButtonFast.setText("Fast");
        jButtonFast.setFocusable(false);
        jButtonFast.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonFast.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonFast.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonFastActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonFast);

        jLabel15.setText("         ");
        jToolBar1.add(jLabel15);

        jButtonCapture.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonCapture.setForeground(new java.awt.Color(51, 51, 255));
        jButtonCapture.setText("Capture");
        jButtonCapture.setFocusable(false);
        jButtonCapture.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonCapture.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonCapture.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCaptureActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonCapture);

        jLabel16.setText("      ");
        jToolBar1.add(jLabel16);

        jButtonAudio.setFont(new java.awt.Font("微软雅黑", 0, 12));
        jButtonAudio.setForeground(new java.awt.Color(51, 51, 255));
        jButtonAudio.setText("Mute  ");
        jButtonAudio.setFocusable(false);
        jButtonAudio.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonAudio.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonAudio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAudioActionPerformed(evt);
            }
        });
        jToolBar1.add(jButtonAudio);

        javax.swing.GroupLayout jPanelPlayControlLayout = new javax.swing.GroupLayout(jPanelPlayControl);
        jPanelPlayControl.setLayout(jPanelPlayControlLayout);
        jPanelPlayControlLayout.setHorizontalGroup(
            jPanelPlayControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPlayControlLayout.createSequentialGroup()
                .addGroup(jPanelPlayControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelPlayControlLayout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 371, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(27, 27, 27)
                        .addComponent(jSliderAudio, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(panelPlay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelPlayControlLayout.setVerticalGroup(
            jPanelPlayControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelPlayControlLayout.createSequentialGroup()
                .addComponent(panelPlay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(jPanelPlayControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSliderAudio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jButtonDownload.setText("下载");
        jButtonDownload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDownloadActionPerformed(evt);
            }
        });

        jButtonSave.setText("保存");
        jButtonSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveActionPerformed(evt);
            }
        });

        jButtonExit.setText("退出");
        jButtonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonExitActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelPlayControl, javax.swing.GroupLayout.PREFERRED_SIZE, 538, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonDownload, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                            .addComponent(jButtonSave, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                            .addComponent(jButtonExit, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)))
                    .addComponent(jPanelTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(249, 249, 249)
                        .addComponent(jButtonDownload)
                        .addGap(30, 30, 30)
                        .addComponent(jButtonSave)
                        .addGap(80, 80, 80)
                        .addComponent(jButtonExit))
                    .addGroup(layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelPlayControl, javax.swing.GroupLayout.PREFERRED_SIZE, 430, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

 /*************************************************
    函数:      "退出"  按钮单击相应函数
    函数描述:  销毁对话框
*************************************************/
    private void jButtonExitActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonExitActionPerformed
    {//GEN-HEADEREND:event_jButtonExitActionPerformed
        StopPlay();
        dispose();
    }//GEN-LAST:event_jButtonExitActionPerformed

/*************************************************
    函数:     "声音进度条"  鼠标离开响应函数
    函数描述:  调节声音
 *************************************************/
    private void jSliderAudioMouseReleased(java.awt.event.MouseEvent evt)//GEN-FIRST:event_jSliderAudioMouseReleased
    {//GEN-HEADEREND:event_jSliderAudioMouseReleased
        	if (m_lPlayHandle.intValue() >= 0)
		{
			if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYAUDIOVOLUME, jSliderAudio.getValue(), null))
			{
				System.out.println(" Set volume Succeed!");
			}
			else
			{
				System.out.println(" Set volume Failed!");
			}
		}
    }//GEN-LAST:event_jSliderAudioMouseReleased

/*************************************************
    函数:      "下载"  按钮单击相应函数
    函数描述:   开始或停止下载文件
*************************************************/
    private void jButtonDownloadActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonDownloadActionPerformed
    {//GEN-HEADEREND:event_jButtonDownloadActionPerformed
        if (m_lLoadHandle.intValue() == -1)
        {
            HCNetSDK.NET_DVR_TIME struStartTime;
            HCNetSDK.NET_DVR_TIME struStopTime;

            struStartTime = new HCNetSDK.NET_DVR_TIME();
            struStopTime = new HCNetSDK.NET_DVR_TIME();
            struStartTime.dwYear = Integer.parseInt(jTextFieldsYear.getText());//开始时间
            struStartTime.dwMonth = Integer.parseInt(jTextFieldsMonth.getText());
            struStartTime.dwDay = Integer.parseInt(jTextFieldsDay.getText());
            struStartTime.dwHour = Integer.parseInt(jTextFieldsHour.getText());
            struStartTime.dwMinute = Integer.parseInt(jTextFieldsMinute.getText());
            struStartTime.dwSecond = Integer.parseInt(jTextFieldsSecond.getText());
            struStopTime.dwYear = Integer.parseInt(jTextFieldeYear.getText());//结束时间
            struStopTime.dwMonth = Integer.parseInt(jTextFieldeMonth.getText());
            struStopTime.dwDay = Integer.parseInt(jTextFieldeDay.getText());
            struStopTime.dwHour = Integer.parseInt(jTextFieldeHour.getText());
            struStopTime.dwMinute = Integer.parseInt(jTextFieldeMinute.getText());
            struStopTime.dwSecond = Integer.parseInt(jTextFieldeSecond.getText());

            m_iChanShowNum = Integer.parseInt(jTextFieldChanNum.getText());

            String sFileName = "c:/DownLoad/" + m_sDeviceIP + m_iChanShowNum + struStartTime.toStringTitle() + struStopTime.toStringTitle() + ".mp4";
            System.out.println(sFileName);
            m_lLoadHandle = hCNetSDK.NET_DVR_GetFileByTime(m_lUserID, new NativeLong(m_iChanShowNum), struStartTime, struStopTime, sFileName);
            if (m_lLoadHandle.intValue() >= 0)
            {
                hCNetSDK.NET_DVR_PlayBackControl(m_lLoadHandle, HCNetSDK.NET_DVR_PLAYSTART, 0, null);
                jButtonDownload.setText("停止下载");
                Downloadtimer = new Timer();//新建定时器
                Downloadtimer.schedule(new DownloadTask(), 0, 5000);//0秒后开始响应函数
            } else
            {
                JOptionPane.showMessageDialog(this, "按时间下载失败");
                System.out.println("laste error " + hCNetSDK.NET_DVR_GetLastError());
                return;
            }
        } 
        else
        {
            hCNetSDK.NET_DVR_StopGetFile(m_lLoadHandle);
            jButtonDownload.setText("下载");
            Downloadtimer.cancel();
        }
    }//GEN-LAST:event_jButtonDownloadActionPerformed

/*************************************************
    函数:      "保存"  按钮单击相应函数
    函数描述:  开始或停止保存文件
*************************************************/
    private void jButtonSaveActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonSaveActionPerformed
    {//GEN-HEADEREND:event_jButtonSaveActionPerformed
        if (m_lPlayHandle.intValue() == -1)
        {
            JOptionPane.showMessageDialog(this, "请先播放文件");
            return;
        }
        if (!m_bTimeSave)
        {
            JFileChooser myJFileChooser = new JFileChooser();
            myJFileChooser.showSaveDialog(this);
            String sFileName = myJFileChooser.getSelectedFile() + ".mp4";
            if (hCNetSDK.NET_DVR_PlayBackSaveData(m_lPlayHandle, sFileName))
            {
                m_bTimeSave = true;
                jButtonSave.setText("停止保存");
            }
        } else
        {
            hCNetSDK.NET_DVR_StopPlayBackSave(m_lPlayHandle);
            m_bTimeSave = false;
            jButtonSave.setText("保存");
        }
    }//GEN-LAST:event_jButtonSaveActionPerformed

 /*************************************************
    函数:      "Play"  按钮单击相应函数
    函数描述:  开始或暂停按时间回放
 *************************************************/
    private void jButtonPlayActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonPlayActionPerformed
    {//GEN-HEADEREND:event_jButtonPlayActionPerformed
       HCNetSDK.NET_DVR_TIME struStartTime;
       HCNetSDK.NET_DVR_TIME struStopTime;

        if (m_lPlayHandle.intValue() == -1)
        {
            m_iChanShowNum = Integer.parseInt(jTextFieldChanNum.getText());

            struStartTime = new HCNetSDK.NET_DVR_TIME();
            struStopTime = new HCNetSDK.NET_DVR_TIME();

            struStartTime.dwYear = Integer.parseInt(jTextFieldsYear.getText());//开始时间
            struStartTime.dwMonth = Integer.parseInt(jTextFieldsMonth.getText());
            struStartTime.dwDay = Integer.parseInt(jTextFieldsDay.getText());
            struStartTime.dwHour = Integer.parseInt(jTextFieldsHour.getText());
            struStartTime.dwMinute = Integer.parseInt(jTextFieldsMinute.getText());
            struStartTime.dwSecond = Integer.parseInt(jTextFieldsSecond.getText());
            struStopTime.dwYear = Integer.parseInt(jTextFieldeYear.getText());//结束时间
            struStopTime.dwMonth = Integer.parseInt(jTextFieldeMonth.getText());
            struStopTime.dwDay = Integer.parseInt(jTextFieldeDay.getText());
            struStopTime.dwHour = Integer.parseInt(jTextFieldeHour.getText());
            struStopTime.dwMinute = Integer.parseInt(jTextFieldeMinute.getText());
            struStopTime.dwSecond = Integer.parseInt(jTextFieldeSecond.getText());

            //获取窗口句柄
            HWND hwnd = new HWND(Native.getComponentPointer(panelPlay));

            m_lPlayHandle = hCNetSDK.NET_DVR_PlayBackByTime(m_lUserID, new NativeLong(m_iChanShowNum), struStartTime, struStopTime, hwnd);

            if (m_lPlayHandle.intValue() == -1)
            {
                JOptionPane.showMessageDialog(this, "按时间回放失败");
                return;
            }
            else{
                //还要调用该接口才能开始回放
                hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYSTART, 0, null);
                System.out.println("开始回放");
            }

            if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYSTARTAUDIO, 0, null))
            {
                m_bSound = true;
                hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYAUDIOVOLUME, (0xffff) / 2, null);
                System.out.println("开始声音");
                jSliderAudio.setValue(50);
                jButtonAudio.setText("Audio");
            } else
            {
                m_bSound = false;
                jButtonAudio.setText("Mute");
            }

            //开始计时器
            Playbacktimer = new Timer();//新建定时器
            Playbacktimer.schedule(new PlaybackTask(), 0, 5000);//0秒后开始响应函数
        } else
        {
            if (m_bPause)
            {
                if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYRESTART, 0, null))
                {
                    System.out.println("Start");
                    jButtonPlay.setText("Pause");
                    m_bPause = false;
                }
            } else
            {
                if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYPAUSE, 0, null))
                {
                    System.out.println("Pause");
                    m_bPause = true;
                    jButtonPlay.setText("Start");
                }
            }
        }
    }//GEN-LAST:event_jButtonPlayActionPerformed

/*************************************************
    函数:      "Stop"  按钮单击相应函数
    函数描述:  停止回放
 *************************************************/
    private void jButtonStopActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonStopActionPerformed
    {//GEN-HEADEREND:event_jButtonStopActionPerformed
               StopPlay();
    }//GEN-LAST:event_jButtonStopActionPerformed

/*************************************************
    函数:      "Slow"  按钮单击相应函数
    函数描述:  慢放
 *************************************************/
    private void jButtonSlowActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonSlowActionPerformed
    {//GEN-HEADEREND:event_jButtonSlowActionPerformed
       	hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, hCNetSDK.NET_DVR_PLAYSLOW, 0, null);
    }//GEN-LAST:event_jButtonSlowActionPerformed

/*************************************************
    函数:      "Fast"  按钮单击相应函数
    函数描述:  快放
 *************************************************/
    private void jButtonFastActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonFastActionPerformed
    {//GEN-HEADEREND:event_jButtonFastActionPerformed
        hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, hCNetSDK.NET_DVR_PLAYFAST, 0, null);
    }//GEN-LAST:event_jButtonFastActionPerformed

/*************************************************
    函数:      "Capture"  按钮单击相应函数
    函数描述:  截图
*************************************************/
    private void jButtonCaptureActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonCaptureActionPerformed
    {//GEN-HEADEREND:event_jButtonCaptureActionPerformed
        if(m_lPlayHandle.intValue() == -1)
        {
            return;
        }
        String sPicName = "C:/Picture/" + m_iChanShowNum + System.currentTimeMillis() + ".bmp";
	if (hCNetSDK.NET_DVR_PlayBackCaptureFile(m_lPlayHandle,sPicName))
	{
		System.out.println("抓图:" + sPicName);
		return;
	}
	else
	{
		JOptionPane.showMessageDialog(this, "抓图失败");
	}
    }//GEN-LAST:event_jButtonCaptureActionPerformed

/*************************************************
    函数:      "Audio"  按钮单击相应函数
    函数描述:  开启或关闭声音
*************************************************/
    private void jButtonAudioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonAudioActionPerformed
    {//GEN-HEADEREND:event_jButtonAudioActionPerformed
       if (m_lPlayHandle.intValue() >= 0)
	{
		if (m_bSound)
		{
			if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYSTOPAUDIO, 0, null))
			{
				m_bSound = false;
				jButtonAudio.setText("Mute");
			}
			else
			{
				System.out.println("Stop audio failed!");
			}
		}
		else
		{
			if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYSTARTAUDIO, 0, null))
			{
				jButtonAudio.setText("Audio");
				m_bSound = true;
			}
			else
			{
				System.out.println("Start audio failed!");
			}
		}
	}
    }//GEN-LAST:event_jButtonAudioActionPerformed

/*************************************************
    函数:      initialDialog
    函数描述:   初始化Dialog
*************************************************/
     private void initialDialog()
     {
         Date today = new Date();//现在时间,用于设置时间框里的时间(当天的0:0:0-23:59:59)
         Calendar now = Calendar.getInstance();//日历对象 
         now.setTime(today); //设置时间

         //开始时间
         jTextFieldsYear.setText(now.get(Calendar.YEAR) + "");
         jTextFieldsMonth.setText((now.get(Calendar.MONTH) + 1) + "");
         jTextFieldsDay.setText(1 + "");
         jTextFieldsHour.setText("0");
         jTextFieldsMinute.setText("0");
         jTextFieldsSecond.setText("0");

         //结束时间
         jTextFieldeYear.setText(now.get(Calendar.YEAR) + "");
         jTextFieldeMonth.setText((now.get(Calendar.MONTH) + 1) + "");
         jTextFieldeDay.setText(now.get(Calendar.DATE) + "");
         jTextFieldeHour.setText("23");
         jTextFieldeMinute.setText("59");
         jTextFieldeSecond.setText("59");

         this.addWindowListener(new WindowAdapter()
         {
            @Override
             public void windowClosing(WindowEvent e)
             {
                 StopPlay();
             }
         });
     }

/*************************************************
    类:      DownloadTask
    类描述:  下载定时器响应函数
 *************************************************/
    class DownloadTask extends java.util.TimerTask
    {
        //定时器函数 
        @Override
        public void run()
        {
            IntByReference nPos = new IntByReference(0);
            hCNetSDK.NET_DVR_PlayBackControl(m_lLoadHandle, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
            if (nPos.getValue() > 100)
            {
                hCNetSDK.NET_DVR_StopGetFile(m_lLoadHandle);
                m_lLoadHandle.setValue(-1);
                jButtonDownload.setText("下载");
                Downloadtimer.cancel();
                JOptionPane.showMessageDialog(null, "由于网络原因或DVR忙,下载异常终止!");
            }
            if (nPos.getValue() == 100)
            {
                hCNetSDK.NET_DVR_StopGetFile(m_lLoadHandle);
                m_lLoadHandle.setValue(-1);
                jButtonDownload.setText("下载");
                Downloadtimer.cancel();
                JOptionPane.showMessageDialog(null, "按时间下载结束!");
            }
        }
    }

/*************************************************
    类:      PlaybackTask
    类描述:  下载定时器响应函数
*************************************************/
    class PlaybackTask extends java.util.TimerTask
    {
        //定时器函数 
        @Override
        public void run()
        {
                IntByReference nPos = new IntByReference(0);
            	if (m_lPlayHandle.intValue() >= 0)
		{
			if (hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos))
			{
                            System.out.println("回放进度" + nPos.getValue());
			}
			else
			{
                             System.out.println("获取回放进度失败");
			}

			if (nPos.getValue() > 100)
			{
				StopPlay();
				JOptionPane.showMessageDialog(null, "由于网络原因或DVR忙,回放异常终止!");
			}
			if (nPos.getValue() == 100)
			{
				StopPlay();
				JOptionPane.showMessageDialog(null, "按时间回放结束");
			}
		}
        }
    }

/*************************************************
    函数:      StopPlay
    函数描述:  停止回放的相关操作
*************************************************/
    private void  StopPlay()
    {
        if (m_lPlayHandle.intValue() >= 0)
	{
		if (m_bTimeSave)
		{
			hCNetSDK.NET_DVR_StopPlayBackSave(m_lPlayHandle);
                        jButtonSave.setText("保存");
			m_bTimeSave = false;
		}

		hCNetSDK.NET_DVR_PlayBackControl(m_lPlayHandle, HCNetSDK.NET_DVR_PLAYSTOPAUDIO, 0, null);
		hCNetSDK.NET_DVR_StopPlayBack(m_lPlayHandle);
		m_lPlayHandle.setValue(-1);

		Playbacktimer.cancel();
                panelPlay.repaint();
	}
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAudio;
    private javax.swing.JButton jButtonCapture;
    private javax.swing.JButton jButtonDownload;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonFast;
    private javax.swing.JButton jButtonPlay;
    private javax.swing.JButton jButtonSave;
    private javax.swing.JButton jButtonSlow;
    private javax.swing.JButton jButtonStop;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelEndTime;
    private javax.swing.JLabel jLabelStartTime;
    private javax.swing.JPanel jPanelPlayControl;
    private javax.swing.JPanel jPanelTime;
    private javax.swing.JSlider jSliderAudio;
    private javax.swing.JTextField jTextFieldChanNum;
    private javax.swing.JTextField jTextFieldeDay;
    private javax.swing.JTextField jTextFieldeHour;
    private javax.swing.JTextField jTextFieldeMinute;
    private javax.swing.JTextField jTextFieldeMonth;
    private javax.swing.JTextField jTextFieldeSecond;
    private javax.swing.JTextField jTextFieldeYear;
    private javax.swing.JTextField jTextFieldsDay;
    private javax.swing.JTextField jTextFieldsHour;
    private javax.swing.JTextField jTextFieldsMinute;
    private javax.swing.JTextField jTextFieldsMonth;
    private javax.swing.JTextField jTextFieldsSecond;
    private javax.swing.JTextField jTextFieldsYear;
    private javax.swing.JToolBar jToolBar1;
    private java.awt.Panel panelPlay;
    // End of variables declaration//GEN-END:variables

}
